$(document).ready(function() {
        $.ajax({
           type: 'POST',
           url: 'indexAjax.jsp',
           data: 'opcion=1',
           cache: 'false',
           success: function(html){
               $("#div_data").html(html);
               renderGrafica();
           }
        });
});

function renderGrafica(){
    
    Highcharts.visualize = function(table, options) {
    // the categories
    options.xAxis.categories = [];
    jQuery('tbody th', table).each( function(i) {
            options.xAxis.categories.push(this.innerHTML);
    });

    // the data series
    options.series = [];
    jQuery('tr', table).each( function(i) {
        var tr = this;
        jQuery('th, td', tr).each( function(j) {
            if (j > 0) { // skip first column
                if (i == 0) { // get the name and init the series
                    options.series[j - 1] = { 
                        name: this.innerHTML,
                        data: []
                    };
                } else { // add values
                    options.series[j - 1].data.push(parseFloat(this.innerHTML));
                }
            }
        });
    });

    var chart = new Highcharts.Chart(options);
  }

  var table = document.getElementById('datos'),
    options = {
               chart: {
                  renderTo: 'div_grafica',
                  defaultSeriesType: 'column'
               },
               title: {
                  text: 'Inscritos por año'
               },
               xAxis: {
                   title: {
                     text: 'Año'
                  }
               },
               yAxis: {
                  title: {
                     text: 'Cantidad'
                  }
               },
               tooltip: {
                  formatter: function() {
                     return '<b>'+ this.series.name +'</b><br/>'+
                        this.y +' '+ this.x.toLowerCase();
                  }
               }
            };
    Highcharts.visualize(table, options);
}

function verTabla(){
    if (document.getElementById('div_data').style.display == 'none'){
        document.getElementById('div_data').style.display = 'block';
    }else{
        document.getElementById('div_data').style.display = 'none';
    }
}